package com._520it.crm.web.controller;

import com._520it.crm.domain.Client;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClientQueryObject;
import com._520it.crm.service.IClientService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 呆 on 2017/10/3.
 */
@Controller
@RequestMapping("/sourceClient")
public class SourceClientController {
    @Autowired
    private IClientService clientService;
    @RequestMapping("")
    public String index(){
        return "sourceClient";
    }


    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(ClientQueryObject qo)
    {
         return clientService.employeeQuery(qo);
    }
    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Client> selectAll()
    {
        return clientService.selectAll();
    }

    /**
     *
     * @param client 前台传过来的客户信息 以此来查询该客户是否存在
     * @param orderBillId 表单id
     * @return
     */
    @RequestMapping("/clientClick")
    @ResponseBody
    public AjaxResult saveApplyClient(Client client,Long orderBillId,String recognizee,String carOwner){
        AjaxResult result = null;
        try {
            clientService.selectClient(client,orderBillId,recognizee,carOwner);
            result = new AjaxResult("客户信息确认成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"该客户已经存在");
        }
        return result;
    }

    /**
     *
     * @param client 前台传过来的被保人信息 以此来查询该客户是否存在
     * @param orderBillId 表单id
     * @return
     */
    @RequestMapping("saveRecognizee")
    @ResponseBody
    public AjaxResult saveRecognizee(Client client,Long orderBillId){
        AjaxResult result = null;
        try {
            clientService.saveRecognizee(client,orderBillId);
            result = new AjaxResult("客户信息确认成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"该客户已经存在");
        }
        return result;
    }

    /**
     * 根据前台传过来的保单id查询 申请人信息
     * @param id 保单id
     * @return
     */
    @RequestMapping("searchApplyClient")
    @ResponseBody
    public Client selectApplyClient(Long id){
        return  clientService.selectApplyClient(id);
    }
    /**
     * 根据前台传过来的保单id查询 被保人信息
     * @param id 保单id
     * @return
     */
    @RequestMapping("searchRecognizee")
    @ResponseBody
    public Client selectRecognizee(Long id){
        return  clientService.selectRecognizee(id);
    }
    /**
     * 根据前台传过来的保单id查询 车主信息
     * @param id 保单id
     * @return
     */
    @RequestMapping("searchCarOwner")
    @ResponseBody
    public Client selectCarOwner(Long id){
        return  clientService.selectCarOwner(id);
    }

    @RequestMapping("/attactClient")
    @ResponseBody
    public AjaxResult attactClient(Long id)
    {
        try {
            clientService.attactClient(id);
            return new AjaxResult(true,"这个客户已经由你负责了,你好好加油!");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("!吸纳失败");
        }

    }




}
